package apiv1

import (
	"github.com/gin-gonic/gin"
	"go-shop-api/internal/service"
	"go-shop-api/pkg/e"
	"go-shop-api/pkg/serializer"
	"net/http"
)

//文件上传

// UploadFile 文件上传
func UploadFile(c *gin.Context) {
	// form文件
	form, err := c.MultipartForm()
	if err != nil {
		c.JSON(http.StatusInternalServerError, serializer.NewResponse(e.ErrorUploadFile, err.Error(), e.TipsErrorUploadFile, nil))
		return
	}
	//上传文件
	c.JSON(http.StatusOK, service.UploadFile(c.DefaultPostForm("path", "/files/"), form))
}

//// UploadSingleFile 上传文件
//func UploadSingleFile(c *gin.Context) {
//	// 单个文件
//	file, err := c.FormFile("file")
//	if err != nil {
//		c.JSON(http.StatusInternalServerError, serializer.NewResponse(e.ErrorUploadFile, err.Error(), e.TipsErrorUploadFile, nil))
//		return
//	}
//	//上传文件
//	c.JSON(http.StatusOK, service.UploadSingleFile(c.DefaultPostForm("path", "/files/"), file))
//}
//
//// UploadMoreFile 上传多个文件
//func UploadMoreFile(c *gin.Context) {
//	// Multipart form
//	form, err := c.MultipartForm()
//	if err != nil {
//		c.JSON(http.StatusInternalServerError, serializer.NewResponse(e.ErrorUploadFile, err.Error(), e.TipsErrorUploadFile, nil))
//		return
//	}
//	//上传文件
//	c.JSON(http.StatusOK, service.UploadMoreFile(c.DefaultPostForm("path", "/files/"), form))
//}
